﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.Web.Shell.Views;
using Churchtoolkit.DataAccess.Common;
using Churchtoolkit.DataAccess.Entities;
using Microsoft.Practices.ServiceLocation;
using Churchtoolkit.Utils.EmailProvider;

namespace Churchtoolkit.Web.Shell.Presenters
{
    public class ActivationPresenter
    {
        MembersRepository _membersrepository;
        Members _member;
        public ActivationPresenter(MembersRepository membersrepository)
        {
            _membersrepository = membersrepository;
        }

        private Members GetMember(int Id)
        {
            EntityResult<Members> result = _membersrepository.Find(m => m.MemberId = Id);
            if (result.RowsCount > 0)
                return result.First();
            return null;
        }

        public void SetMemberId(int id)
        {
           _member = GetMember(id);
        }

        public bool IsMemberExists()
        {
            if (_member != null)
            {
                return true;
            }
            else
                return false;
        }

        public bool IsMemberAlreadyActive()
        {
            if (_member.IsActive == true)
            {
                return true;
            }
            else
                return false;
        }
        public void ActivateMember()
        {
            _member.IsActive = true;
            _membersrepository.Update(_member);
 
        }

    }
}
